package com.zhyl.demo.controller;

import com.zhyl.demo.entity.BackConsultations;
import com.zhyl.demo.service.BackConsultationsService;
import com.zhyl.demo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/backConsultations")
public class BackConsultationsController {
  private final BackConsultationsService backConsultationsService;
  @Autowired
  public BackConsultationsController(BackConsultationsService backConsultationsService) {
    this.backConsultationsService = backConsultationsService;
  }

  @RequestMapping("/saveConsultation")
  public Result saveConsultation(@RequestBody BackConsultations backConsultations){
    if (backConsultations==null){
      return Result.error("-1","参数错误");
    }
    Boolean b = backConsultationsService.saveConsultation(backConsultations);
    if (b){
      return Result.success();
    }else {
      return Result.error("-1","保存失败");
    }
  }

  @RequestMapping("/getSaveConsultation")
  public Result getSaveConsultation(int appointmentId)
  {
    if (appointmentId<=0){
      return Result.error("-1","参数错误");
    }
    List<BackConsultations> saveConsultationList = backConsultationsService.getSaveConsultation(appointmentId);
    if (saveConsultationList.isEmpty()) {
        return Result.error("-1", "没有找到相关记录");
    }
    BackConsultations saveConsultation = saveConsultationList.get(0);
    return Result.success(saveConsultation);
  }

}
